﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Service.Work;
using SystmicFunction.IRMHelper;

namespace Web.Controllers
{
    public class AsyController : AsyncController
    {

        public void LongPollingAsync(String key)
        {

            //告诉ASP.NET接下来将进行一个异步操作
            AsyncManager.OutstandingOperations.Increment();

            var worker = new Worker
            {
                Key = key,
            };
            worker.OnGetDataCompleted += (sender, e) =>
            {
                AsyncManager.Parameters["data"] = e;
                //告诉ASP.NET异步操作已完成，进行LongPollingCompleted方法的调用
                AsyncManager.OutstandingOperations.Decrement();
            };
            worker.GetDataAsync();
        }

        public ActionResult LongPollingCompleted(Object data)
        {
            return Json(data,
            JsonRequestBehavior.AllowGet);
        }

    }
}
